package cn.com.lms.business.exam.persistence.repository;


import cn.com.lms.business.exam.persistence.entity.EmployeePaperSubject;

import com.bnzj.core.persistence.repository.BaseRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;
import java.util.Collection;
import java.util.List;
import java.util.Map;

@Repository
public interface EmployeePaperSubjectRepository extends BaseRepository<EmployeePaperSubject, Long> {

    @Query(value = " select ps.id, ps.employee_paper_id as employeePaperId, ps.subject_id as subjectId,ps.type,ps.subject,ps.options,ps.images,ps.right_answer as rightAnswer,ps.parse ,ps.subject_score as subjectScore," +
            " ps.employee_id as  employeeId, ps.sort_id as sortId,ps.answer,ps.score,ps.create_time as createTime,ps.modify_time as modifyTime " +
            " from bnz_exam_employee_paper_subject ps where ps.employee_paper_id=?1 order by sort_id ",nativeQuery = true)
    List<Map<String, Object>> selectEmployeePaperSubjectByEmployeePaperId(Long employeePaperId);


    @Transactional
    @Modifying
    @Query(value = "delete from bnz_exam_employee_paper_subject where employee_paper_id =:employeePaperId and subject_id in (:collection)", nativeQuery = true)
    int deleteBySubjectList(@Param("employeePaperId") Long employeePaperId , @Param("collection") Collection<Long> collection) ;


}
